package sc.tool.sqlgen.branchinfo;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.List;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.io.SAXReader;
import org.dom4j.tree.DefaultElement;
import org.dom4j.xpath.DefaultXPath;

import sc.prototype.common.ConsoleUtil;

/**
 *
 * <p>TODO:注释</p>
 *
 * @author Zhang Yun
 * @version $Id: Processor.java, v 0.1 2012-11-3 下午9:58:42 User Exp $
 */
public class BranchInfoProcessor implements ConsoleUtil {

    public void process() {
        try {
            //1.导入支行原始信息
            ParseResult parseResult = new Importer().importFile("D:/WeibopayMemo/出款服务FOS/联行号信息.xml");
            Console.info("parseResult: {}", parseResult);
            ResultHolder.setParseResult(parseResult);

            List<BranchInfo> dbDataList = DataService.loadBranchInfoFromDb();
            Console.info("branchinfo.db got: {}", dbDataList.size());

            //2.进行比较
            CompareResult compareResult = new Comparator().compare(dbDataList, parseResult.getSuccessResults());
            Console.info("compareResult: {}", compareResult);
            ResultHolder.setCompareResult(compareResult);

            //3.导出比较后结果
            //            new Exporter().export();
            new Exporter().exportXlsx();
        } catch (Exception e) {
            Console.error("", e);
        } finally {
            ResultHolder.clear();
        }

    }

    @SuppressWarnings("unchecked")
    public void test() throws FileNotFoundException, DocumentException {
        String filePath = "D:/WeibopayMemo/出款服务FOS/联行号信息.xml";
        SAXReader reader = new SAXReader();
        Document doc = reader.read(new FileInputStream(filePath));
        DefaultXPath xpath = new DefaultXPath("//ibps");
        List<DefaultElement> list = xpath.selectNodes(doc);
        for (DefaultElement element : list) {
            Console.info("{}", element);
        }

    }

    public static void main(String[] args) {
        try {
            BranchInfoProcessor processor = new BranchInfoProcessor();
            //        processor.process();
            processor.test();
        } catch (Exception e) {
            Console.error("", e);
        }
    }

}
